package cn.agiledata.bank.common.bean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.agiledata.bank.common.util.WeatherUtil;
import com.vnv.infrastructure.action.IPBBaseAction;

public abstract class CommonAction extends IPBBaseAction {
	protected String returnString;
	
	public static String CLEANORNOT = "clean";
	
	public abstract String getIfWrongReturnString();
	
	public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		WeatherUtil.setPageModual(mapping, request);
		// TODO Auto-generated method stub
		ActionForward af = new ActionForward();

			try {
				if (CLEANORNOT.equals(request.getAttribute(CLEANORNOT))
						||CLEANORNOT.equals(request.getParameter(CLEANORNOT))){
					WeatherUtil.cleanForm(actionForm);
					request.setAttribute(CLEANORNOT, null);
				}
				
				af = super.execute(mapping, actionForm, request, response);
				
				if (CLEANORNOT.equals(request.getAttribute(CLEANORNOT))
						||CLEANORNOT.equals(request.getParameter(CLEANORNOT))){
					WeatherUtil.cleanForm(actionForm);
					//request.setAttribute(CLEANORNOT, null);
				}
			} catch (Exception e) {
				// TODO: handle exception
				request.setAttribute("errorMsg", e.getMessage());
				return mapping.findForward(getIfWrongReturnString());
			}

		return af;
	}

}
